com.appventive.pausemediator
Class Mediator

java.lang.Object
  extended by android.content.BroadcastReceiver
      extended by com.appventive.pausemediator.Mediator

public abstract class Mediator
extends android.content.BroadcastReceiver

Used by an app that wants to offer pause/resume control to other apps. For instance, this is used in the lock screen modes of both "ICE: In Case of Emergency" and "Executive Assistant" to allow other apps (mainly alarm clocks) to temporarily prevent the custom lock screen from coming up. When the alarm is going off, the lock screen is "paused", then when the alarm is dismissed, the lock screen is "resumed".

Author:
Appventive LLC

Field Summary
static java.lang.String LabelExtra
          the name of the app initiating the pause.
static java.lang.String PackageExtra
          the package initiating the pause.
static java.lang.String Pause
          Action to initiate the pause.
static java.lang.String PauseGranted
          Action send to a Requester to grant permission to pause.
static java.lang.String PauseRequest
          Action broadcast to request permission to pause.
static java.lang.String Resume
          Action to initiate a resume.
static java.lang.String SecretExtra
          the secret generated by the Mediator.
 
Constructor Summary
Mediator()
           
 
Method Summary
 int generateSecret()
           
static android.content.IntentFilter getIntentFilter()
           
abstract  void handlePause(android.content.Context context, java.lang.String pkg, java.lang.String label)
          This is what your app does when it gets "paused".
abstract  void handleResume(android.content.Context context)
          This is what your app does when it gets "resumed"
 boolean hasPermissionToPause(android.content.Context context, java.lang.String pkg)
          Override this to conditionally grant or deny permission to specific packages
 void onReceive(android.content.Context context, android.content.Intent intent)
           
 boolean pauseEnabled(android.content.Context context)
          Override this to conditionally enable or disable the PauseMediator as needed.
 
Methods inherited from class android.content.BroadcastReceiver
abortBroadcast, clearAbortBroadcast, getAbortBroadcast, getDebugUnregister, getResultCode, getResultData, getResultExtras, isInitialStickyBroadcast, isOrderedBroadcast, peekService, setDebugUnregister, setOrderedHint, setResult, setResultCode, setResultData, setResultExtras
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PauseRequest

public static final java.lang.String PauseRequest
Action broadcast to request permission to pause. Can be sent by any app.

See Also:
Constant Field Values

Pause

public static final java.lang.String Pause
Action to initiate the pause. The Intent must be limited to this package (see Intent.setPackage) and must include the SecretExtra that was sent to the Requester with the PauseGranted action.

See Also:
Constant Field Values

Resume

public static final java.lang.String Resume
Action to initiate a resume. Can be sent by any app.

See Also:
Constant Field Values

PauseGranted

public static final java.lang.String PauseGranted
Action send to a Requester to grant permission to pause. The Intent must be limited to the package specified in the PauseRequest (see Intent.setPackage) and must include a SecretExtra.

See Also:
Constant Field Values

LabelExtra

public static final java.lang.String LabelExtra
the name of the app initiating the pause. Passed with the Pause action.

See Also:
Constant Field Values

PackageExtra

public static final java.lang.String PackageExtra
the package initiating the pause. Passed with the Pause action.

See Also:
Constant Field Values

SecretExtra

public static final java.lang.String SecretExtra
the secret generated by the Mediator. Sent with PauseGranted and returned with Pause.

See Also:
Constant Field Values
Constructor Detail

Mediator

public Mediator()
Method Detail

getIntentFilter

public static android.content.IntentFilter getIntentFilter()
Returns:
an IntentFilter that can be used to dynamically register the Mediator. If declaring the Mediator in the Android Manifest, use: <intent-filter> <action android:name="com.appventive.pausemediator.pause_request"></action> <action android:name="com.appventive.pausemediator.pause"></action> <action android:name="com.appventive.pausemediator.resume"></action> </intent-filter>

generateSecret

public int generateSecret()
Returns:
the value to be used as the SecretExtra

onReceive

public void onReceive(android.content.Context context,
                      android.content.Intent intent)
Specified by:
onReceive in class android.content.BroadcastReceiver

pauseEnabled

public boolean pauseEnabled(android.content.Context context)
Override this to conditionally enable or disable the PauseMediator as needed.

Parameters:
context -
Returns:
true if the Mediator is enabled. When disabled, all pause requests are ignored.

hasPermissionToPause

public boolean hasPermissionToPause(android.content.Context context,
                                    java.lang.String pkg)
Override this to conditionally grant or deny permission to specific packages

Parameters:
context -
pkg - the name of the package
Returns:
true if pkg has permission to pause

handlePause

public abstract void handlePause(android.content.Context context,
                                 java.lang.String pkg,
                                 java.lang.String label)
This is what your app does when it gets "paused". Optionally use label and/or pkg to keep track of which app paused your app. You may want to create a status bar notification letting the user know which app is responsible for initiating the pause.

Parameters:
context -
pkg - the name of the package that was granted the pause permission
label - the application name of the package (e.g., as shown in a launcher shortcut)

handleResume

public abstract void handleResume(android.content.Context context)
This is what your app does when it gets "resumed"

Parameters:
context -